Array.prototype.myReduce = function (func, init) {
  var pre = this[0],
    i = 1;
  //判断有没有传入初始值
  if (init) {
    pre = init;
    i = 0;
  }
  while (i < this.length) {
    pre = func(pre, this[i], i);
    i++;
  }
  return pre;
}
var arr = [1, 2, 3, 4, 5, 1, 1];
var newAr = arr.myReduce(function (a, b, index) {
  return a + b
})
console.log(newAr)